function init() {
    $(function () {
        var user = [
            { workId: "GD2021060012", workStatu: "待分配", category: '房屋维修', repair: '王**', repairPositon: 'A区02#一单元5层602', app: 'App', rTime: '20210627 09:20:34', admin: 'admin01', rMan: '李**' },
            { workId: "GD2021060013", workStatu: "待接单", category: '房屋维修', repair: '李**', repairPositon: 'B区06#二单元3层301', app: 'App', rTime: '20210627 09:20:34', admin: 'admin01', rMan: '舒**' },
            { workId: "GD2021060014", workStatu: "待接单", category: '房屋维修', repair: '吴**', repairPositon: 'A区B2005', app: 'App', rTime: '20210627 09:20:34', admin: 'admin02', rMan: '李**' },
            { workId: "GD2021060015", workStatu: "待接单", category: '房屋维修', repair: '李**', repairPositon: 'B区C3010', app: 'App', rTime: '20210627 09:20:34', admin: 'admin03', rMan: '李**' },
            { workId: "GD2021060016", workStatu: "待接单", category: '房屋维修', repair: '张**', repairPositon: 'A区公共区域', app: 'App', rTime: '20210627 09:20:34', admin: 'admin04', rMan: '李**' },
            { workId: "GD2021060017", workStatu: "待接单", category: '房屋维修', repair: '徐**', repairPositon: 'B区公共区域', app: 'App', rTime: '20210627 09:20:34', admin: 'admin05', rMan: '李**' },
            { workId: "GD2021060018", workStatu: "待接单", category: '房屋维修', repair: '黄**', repairPositon: 'A区公共区域', app: 'App', rTime: '20210627 09:20:34', admin: 'admin016', rMan: '赵**' },
            { workId: "GD2021060019", workStatu: "待分配", category: '房屋维修', repair: '刘**', repairPositon: 'B区04#楼电梯', app: 'App', rTime: '20210627 09: 20: 34', admin: 'admin08', rMan: '张** ' },
            { workId: "GD2021060020", workStatu: "已完成", category: '房屋维修', repair: '赵**', repairPositon: 'B区05#楼电梯', app: 'App', rTime: '20210627 09:20:34', admin: 'admin012', rMan: '刘**' },
            { workId: "GD2021060021", workStatu: "已完成", category: '房屋维修', repair: '李**', repairPositon: 'A区南2C出入口', app: 'App', rTime: '20210627 09:20:34', admin: 'admin014', rMan: '王**' },
            { workId: "GD2021060022", workStatu: "已完成", category: '房屋维修', repair: '李**', repairPositon: 'A区05#楼一单元', app: 'App', rTime: '20210627 09:20:34', admin: 'admin012', rMan: '李**' },
            { workId: "GD2021060023", workStatu: "已完成", category: '房屋维修', repair: '李**', repairPositon: 'B区01#设备泵房', app: 'App', rTime: '20210627 09:20:34', admin: 'admin01', rMan: '福**' },
            { workId: "GD2021060024", workStatu: "已完成", category: '房屋维修', repair: '李**', repairPositon: 'A区公共区域', app: 'App', rTime: '20210627 09:20:34', admin: 'admin012', rMan: '徐**' },
            { workId: "GD2021060025", workStatu: "已关闭", category: '房屋维修', repair: '李**', repairPositon: 'B区03#二单元3层301', app: 'App', rTime: '20210627 09:20:34', admin: 'admin01', rMan: '李**' },
            { workId: "GD2021060026", workStatu: "已作废", category: '房屋维修', repair: '李**', repairPositon: 'A区06#一单元4层501', app: 'App', rTime: '20210627 09:20:34', admin: 'admin01', rMan: '李**' }
        ]
        var operid = -1;
        var perSize = 10; //每页显示的条数
        var currentPage = 1; //当前显示的页数
        var totalPage = -1; //总共的页数
        var newArr = [];

        var mytime = new Date().toLocaleString();
        function displayUserTable() {
            $("#userTable").html("");
            var start = (currentPage - 1) * perSize;
            var end = start + perSize;
            var a = 0;
            var b = 0;
            var c = 0;
            var d = 0;
            var e = 0;
            var outHtml = "";
            for (let i = 0; i < user.length; i++) {
                user[i].id = i + 1;
            }
            for (var i = start; i < end && i < user.length; i++) {
                if (user[i].workStatu == '待分配') {
                    a++
                    outHtml +=
                        "<tr>" +
                        "<td>" + user[i].id + "</td>" +
                        "<td>" + user[i].workId + "</td>" +
                        "<td class=\'color\'>" + user[i].workStatu + "</td>" +
                        "<td>" + user[i].category + "</td>" +
                        "<td>" + user[i].repair + "</td>" +
                        "<td>" + user[i].repairPositon + "</td>" +
                        "<td>" + user[i].app + "</td>" +
                        "<td>" + user[i].rTime + "</td>" +
                        "<td>" + user[i].admin + "</td>" +
                        "<td>" + user[i].rMan + "</td>" +
                        "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                        "</tr>";
                } else if (user[i].workStatu == '待接单') {
                    b++
                    outHtml +=
                        "<tr>" +
                        "<td>" + user[i].id + "</td>" +
                        "<td>" + user[i].workId + "</td>" +
                        "<td class=\'color2\'>" + user[i].workStatu + "</td>" +
                        "<td>" + user[i].category + "</td>" +
                        "<td>" + user[i].repair + "</td>" +
                        "<td>" + user[i].repairPositon + "</td>" +
                        "<td>" + user[i].app + "</td>" +
                        "<td>" + user[i].rTime + "</td>" +
                        "<td>" + user[i].admin + "</td>" +
                        "<td>" + user[i].rMan + "</td>" +
                        "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                        "</tr>";
                }
                else if (user[i].workStatu == '已完成') {
                    d++
                    outHtml +=
                        "<tr>" +
                        "<td>" + user[i].id + "</td>" +
                        "<td>" + user[i].workId + "</td>" +
                        "<td class=\'color3\'>" + user[i].workStatu + "</td>" +
                        "<td>" + user[i].category + "</td>" +
                        "<td>" + user[i].repair + "</td>" +
                        "<td>" + user[i].repairPositon + "</td>" +
                        "<td>" + user[i].app + "</td>" +
                        "<td>" + user[i].rTime + "</td>" +
                        "<td>" + user[i].admin + "</td>" +
                        "<td>" + user[i].rMan + "</td>" +
                        "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                        "</tr>";
                }
                else if (user[i].workStatu == '已关闭') {
                    c++
                    outHtml +=
                        "<tr>" +
                        "<td>" + user[i].id + "</td>" +
                        "<td>" + user[i].workId + "</td>" +
                        "<td class=\'color4\'>" + user[i].workStatu + "</td>" +
                        "<td>" + user[i].category + "</td>" +
                        "<td>" + user[i].repair + "</td>" +
                        "<td>" + user[i].repairPositon + "</td>" +
                        "<td>" + user[i].app + "</td>" +
                        "<td>" + user[i].rTime + "</td>" +
                        "<td>" + user[i].admin + "</td>" +
                        "<td>" + user[i].rMan + "</td>" +
                        "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                        "</tr>";
                }
                else {
                    e++
                    outHtml +=
                        "<tr>" +
                        "<td>" + user[i].id + "</td>" +
                        "<td>" + user[i].workId + "</td>" +
                        "<td>" + user[i].workStatu + "</td>" +
                        "<td>" + user[i].category + "</td>" +
                        "<td>" + user[i].repair + "</td>" +
                        "<td>" + user[i].repairPositon + "</td>" +
                        "<td>" + user[i].app + "</td>" +
                        "<td>" + user[i].rTime + "</td>" +
                        "<td>" + user[i].admin + "</td>" +
                        "<td>" + user[i].rMan + "</td>" +
                        "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                        "</tr>";
                }
            }
            $("#userTable").html(outHtml);
            $('#a').html(a); $('#b').html(b); $('#c').html(c); $('#d').html(d); $('#e').html(e);
            $('#sum').html(a + b + c + d + e)
        }
        displayUserTable();
        function pagebar() {
            totalPage = Math.ceil(user.length / perSize);
            if (currentPage > totalPage) {
                currentPage = totalPage;
            }
            $("#divPage").html("");
            var str = '';
            for (var i = 0; i < totalPage; i++) {
                if (currentPage == (i + 1)) {
                    str += "<button class=\"btn page btn-primary page\">" + (i + 1) + "</button>";
                } else {
                    str += "<button class=\"btn page btn-default page\">" + (i + 1) + "</button>";
                }
            }
            $("#divPage").html(str);
        }
        function pagebar2() {
            totalPage = Math.ceil(newArr.length / perSize);
            console.log(totalPage);
            console.log(newArr);
            if (currentPage > totalPage) {
                currentPage = totalPage;
            }
            $("#divPage").html("");
            var str = '';
            for (var i = 0; i < totalPage; i++) {
                if (currentPage == (i + 1)) {
                    str += "<button class=\"btn page1 btn-primary page\">" + (i + 1) + "</button>";
                } else {
                    str += "<button class=\"btn page2 btn-default page\">" + (i + 1) + "</button>";
                }

            }
            $("#divPage").html(str);
        }
        pagebar()
        function pageClick() {
            $("#divPage").on("click", ".page", function () {
                $('.page').removeClass('btn-primary');
                $(this).addClass('btn-primary');
                currentPage = Number(this.innerText);
                displayUserTable();
            });
        }
        pageClick()
        function add() {
            $('#add').click(function () {
                $('#addUser').modal('show');
                operid = -1;
                $('#moren').prop('selected', 'selected')
            })
            $('#btnAdd').click(function () {
                var text1 = $("#txt1").val();
                var text2 = $("#txt2").val();
                var text3 = $("#txt3").val();
                var text4 = $("#txt4").val();
                var text5 = $("#txt5").val();
                var text6 = $("#txt6").val();
                var text7 = $("#txt7").val();
                var text8 = $("#txt8").val();
                var text9 = $("#txt9").val();
                var obj = {
                    'workId': text1, "workStatu": text2, "category": text3,
                    'repair': text4, 'repairPositon': text5, 'app': text6, 'rTime': text7,
                    'admin': text8, 'rMan': text9
                }
                if (operid == -1) {
                    user.push(obj);
                } else {
                    user.splice(operid, 1, obj);
                }
                $('#addUser').modal('hide');
                displayUserTable();
                pagebar();
            })
            $('#btnCancel').click(function () {
                $('#addUser').modal('hide');
                displayUserTable();
                pagebar();
            })
        }
        add()
        function edit() {
            $("#userTable").on('click', '.edit', function () {
                var index = $(this).attr('data-index');
                operid = index;
                $('#addUser').modal('show');
                $("#txt1").val(user[index].workId);
                $("#txt2").val(user[index].workStatu);
                $("#txt3").val(user[index].category);
                $("#txt4").val(user[index].repair);
                $("#txt5").val(user[index].repairPositon);
                $("#txt6").val(user[index].app);
                $("#txt7").val(user[index].rTime);
                $("#txt8").val(user[index].admin);
                $("#txt9").val(user[index].rMan);
            })
            $('#moren').prop('selected', 'selected')
        }
        edit()
        function del() {
            $("#userTable").on('click', '.del', function () {
                var index = $(this).attr('data-index');
                $('#delUser').modal('show');
                $('#btnDel').on('click', function () {
                    user.splice(index, 1);
                    pagebar();
                    $('#btnDel').unbind();
                    $('#btnCancel2').unbind();
                    $('#delUser').modal('hide');
                    if ($("#userTable").html() == '') {
                        var outHtml = "<div><p>你的内容为空</p></div>";
                        $("#userTable").html(outHtml);
                    } else {
                        displayUserTable();
                    }
                })
                $('#btnCancel2').on('click', function () {
                    $('#delUser').modal('hide');
                    $('#btnDel').unbind();
                    $('#btnCancel2').unbind();
                })
                $('#moren').prop('selected', 'selected')
            })

        }
        del();
        function search() {
            $('.search1').click(function () {
                newArr = []
                var shuru = $(this).prev().val();
                var result = new RegExp(shuru);
                var outHtml = '';
                var findConfirm = 0;
                if (shuru != '') {
                    for (var i = 0; i < user.length; i++) {
                        var match = user[i].workId;
                        newArr.push(user[i])
                        if (result.test(match)) {
                            outHtml +=
                                "<tr>" +
                                "<td>" + user[i].id + "</td>" +
                                "<td>" + user[i].workId + "</td>" +
                                "<td>" + user[i].workStatu + "</td>" +
                                "<td>" + user[i].category + "</td>" +
                                "<td>" + user[i].repair + "</td>" +
                                "<td>" + user[i].repairPositon + "</td>" +
                                "<td>" + user[i].app + "</td>" +
                                "<td>" + user[i].rTime + "</td>" +
                                "<td>" + user[i].admin + "</td>" +
                                "<td>" + user[i].rMan + "</td>" +
                                "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                                "</tr>";
                            $("#userTable").html(outHtml);
                            $('.search2').prev().val('');
                            findConfirm = 1;
                            pagebar2()
                            continue;
                        }
                    }
                    if (findConfirm == 0) {
                        outHtml = "<div><p>未找到你要的内容</p><button class=\"btn btn-default back \">返回</button></div>";
                        $("#userTable").html(outHtml);
                        $('.search1').prev().val('');
                        $('.back').on('click', function () {
                            displayUserTable()
                        })
                    }
                };
            })
            $('.search2').click(function () {
                newArr = []
                var shuru = $(this).prev().val();
                var result = new RegExp(shuru);
                var outHtml = '';
                var findConfirm = 0;
                if (shuru != '') {
                    for (var i = 0; i < user.length; i++) {
                        var match = user[i].repair;
                        if (result.test(match)) {
                            newArr.push(user[i])
                            outHtml +=
                                "<tr>" +
                                "<td>" + user[i].id + "</td>" +
                                "<td>" + user[i].workId + "</td>" +
                                "<td>" + user[i].workStatu + "</td>" +
                                "<td>" + user[i].category + "</td>" +
                                "<td>" + user[i].repair + "</td>" +
                                "<td>" + user[i].repairPositon + "</td>" +
                                "<td>" + user[i].app + "</td>" +
                                "<td>" + user[i].rTime + "</td>" +
                                "<td>" + user[i].admin + "</td>" +
                                "<td>" + user[i].rMan + "</td>" +
                                "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                                "</tr>";
                            $("#userTable").html(outHtml);
                            $('.search2').prev().val('');
                            findConfirm = 1;
                            pagebar2()
                            continue;
                        }
                    }
                    if (findConfirm == 0) {
                        outHtml = "<div><p>未找到你要的内容</p><button class=\"btn btn-default back \">返回</button></div>";
                        $("#userTable").html(outHtml);
                        $('.search1').prev().val('');
                        $('.back').on('click', function () {
                            displayUserTable()
                        })
                    }
                };
            })
            $('.search3').click(function () {
                newArr = []
                var shuru = $(this).prev().val();
                var result = new RegExp(shuru);
                var outHtml = '';
                var findConfirm = 0;
                if (shuru != '') {
                    for (var i = 0; i < user.length; i++) {
                        var match = user[i].rMan;
                        if (result.test(match)) {
                            newArr.push(user[i])
                            outHtml +=
                                "<tr>" +
                                "<td>" + user[i].id + "</td>" +
                                "<td>" + user[i].workId + "</td>" +
                                "<td>" + user[i].workStatu + "</td>" +
                                "<td>" + user[i].category + "</td>" +
                                "<td>" + user[i].repair + "</td>" +
                                "<td>" + user[i].repairPositon + "</td>" +
                                "<td>" + user[i].app + "</td>" +
                                "<td>" + user[i].rTime + "</td>" +
                                "<td>" + user[i].admin + "</td>" +
                                "<td>" + user[i].rMan + "</td>" +
                                "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                                "</tr>";
                            $("#userTable").html(outHtml);
                            $('.search3').prev().val('');
                            findConfirm = 1;
                            pagebar2()
                            continue;
                        }
                    }
                    if (findConfirm == 0) {
                        outHtml = "<div><p>未找到你要的内容</p><button class=\"btn btn-default back \">返回</button></div>";
                        $("#userTable").html(outHtml);
                        $('.search3').prev().val('');
                        $('.back').on('click', function () {
                            displayUserTable()
                        })
                    }
                };
            })
            $('#search4').change(function () {
                newArr = []
                var shuru = $(this).val();
                var result = new RegExp(shuru);
                var outHtml = '';
                var findConfirm = 0;
                if (shuru != '') {
                    for (var i = 0; i < user.length; i++) {
                        var match = user[i].workStatu;
                        if (result.test(match)) {
                            newArr.push(user[i])
                            outHtml +=
                                "<tr>" +
                                "<td>" + user[i].id + "</td>" +
                                "<td>" + user[i].workId + "</td>" +
                                "<td>" + user[i].workStatu + "</td>" +
                                "<td>" + user[i].category + "</td>" +
                                "<td>" + user[i].repair + "</td>" +
                                "<td>" + user[i].repairPositon + "</td>" +
                                "<td>" + user[i].app + "</td>" +
                                "<td>" + user[i].rTime + "</td>" +
                                "<td>" + user[i].admin + "</td>" +
                                "<td>" + user[i].rMan + "</td>" +
                                "<td><button class=\"btn btn-default del\" data-index='" + i + "'>删除</button><button class=\"btn btn-default edit\"  data-index='" + i + "'>编辑</button></td>" +
                                "</tr>";
                            $("#userTable").html(outHtml);
                            $('#search4').prev().val('');
                            findConfirm = 1;
                            pagebar2()
                            continue;
                        }
                        else if (result == '/全部/') {
                            displayUserTable();
                            pagebar()
                            break
                        }
                    }
                    if (findConfirm == 0 && result != '/全部/') {
                        outHtml = "<div><p>未找到你要的内容</p><button class=\"btn btn-default back \">返回</button></div>";
                        $("#userTable").html(outHtml);
                        $('.search3').prev().val('');
                        $('.back').on('click', function () {
                            displayUserTable();

                        })
                    }
                };
            })
        }
        search();
        function reset() {
            displayUserTable()
            pagebar()
        }
        $('#reset').click(function () {
            reset(),
                alert('已重置网页')
            $('#moren').prop('selected', 'selected')
            $('input').val('');
        }
        )
    })
}
init()







